#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "m_mysql.h"

MYSQL* m_mysql_create_connect(char *host, char *user, char *pass, char *db, 
        unsigned int port)
{
    MYSQL *mysql = NULL, conn;

    mysql = mysql_init(&conn);
    if (NULL == mysql)
        return NULL;

    mysql->reconnect = 1;

    if (!mysql_real_connect(mysql, host, user, pass, db, port, NULL, 0))
        return NULL;
    return mysql;
}

void m_mysql_close_connect(MYSQL *mysql)
{
    if (mysql)
    {
        mysql_close(mysql);
        mysql = NULL;
    }
    return ;
}

int m_mysql_query(MYSQL *mysql, char *query)
{
    if (mysql_real_query(mysql, query, strlen(query)))
        return 1;
    return 0;
}

MYSQL_RES* m_mysql_print_res(MYSQL *mysql)
{
    MYSQL_RES *res;

    res = mysql_store_result(mysql); // store query result
    if (NULL == res || 0 == mysql_num_rows(res))
        return NULL;


    return res;
}
